#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QSharedDataPointer>
#include <QTimer>
#include <QThread>
#include "qcustomplot.h"
#include "serialcommunication.h"
#include "filesavemanager.h"

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

signals:
    void request_to_open_port(QString, const BuadRate_t);
    void request_to_close_port();
    void request_to_write_data(QByteArray);
    void request_for_save_path();

private slots:
    void on_pushButton_SaveImg_clicked();

    void on_pushButton_ClearImg_clicked();

    void on_pushButton_StorageDepth_clicked();

    void on_pushButton_Connect_clicked();

    void on_pushButton_SampleRate_clicked();

    void update_data(const QStringList data_lst);

    void updateSerialPorts();

    void afterPortOpened(SerialOpenResult ret);

    void afterPortClosed();

    void afterSavePathGot(QString filename);

    void refreshCurve();

private:
    Ui::MainWindow *ui;
    QList<QSerialPortInfo> mSerialPorts;
    SerialCommunication* mCommunication;
    FileSaveManager* mFileSaver;
    QTimer* mSerialScanTimer;
    QTimer* mRefreshCurveTimer;
    QSharedPointer<QCPGraphDataContainer> mData;
    bool port_connected = false;
    QThread* mSerialThread;
    uint32_t storage_depth;
};
#endif // MAINWINDOW_H
